<?php
/**
 * Created by PhpStorm.
 * User: linyh
 * Date: 2017/11/25 0025 10:13
 */
?>
<link href="/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet" />

<section class="content-header">
    <h1>
        贷款利率
    </h1>
</section>

<!-- Main content -->
<section class="content">
<div class="row">
    <div class="col-md-12">
        <!-- general form elements -->
        <div class="box box-default">
            <!-- /.box-header -->
            <!-- form start -->
            <form id="form" role="form" class="form-horizontal">
                <div class="box-body">
                    <div class="form-group hidden" id="1">
                        <label for="input1" class="col-sm-5 control-label">贷款一财年</label>
                        <div class="col-sm-4">
                        <input id="input1" class="form-control" type="number" step="0.01" max="0.5" name="loan[1]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="2">
                        <label for="input2" class="col-sm-5 control-label">贷款二财年</label>
                        <div class="col-sm-4">
                        <input id="input2" class="form-control" type="number" step="0.01" max="0.5" name="loan[2]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="3">
                        <label for="input3" class="col-sm-5 control-label">贷款三财年</label>
                        <div class="col-sm-4">
                        <input id="input3" class="form-control" type="number" step="0.01" max="0.5" name="loan[3]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="4">
                        <label for="input4" class="col-sm-5 control-label">贷款四财年</label>
                        <div class="col-sm-4">
                        <input id="input4" class="form-control" type="number" step="0.01" max="0.5" name="loan[4]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="5">
                        <label for="input5" class="col-sm-5 control-label">贷款五财年</label>
                        <div class="col-sm-4">
                        <input id="input5" class="form-control" type="number" step="0.01" max="1" name="loan[5]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="10">
                        <label for="input10" class="col-sm-5 control-label">贷款十财年</label>
                        <div class="col-sm-4">
                        <input id="input10" class="form-control" type="number" step="0.01" max="1" name="loan[10]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                    <div class="form-group hidden" id="20">
                        <label for="input20" class="col-sm-5 control-label">贷款二十财年</label>
                        <div class="col-sm-4">
                        <input id="input20" class="form-control" type="number" step="0.01" max="2" name="loan[20]" placeholder="请输入贷款利率">
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->

                <div class="box-footer text-center">
                    <button type="submit" class="btn btn-success">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
</section>

<script>

$(function() {
    for(var i in global.user.country.loanRates) {
        var rate = global.user.country.loanRates[i];
        $('[name="loan[' + rate.cycle + ']"]').val(rate.loan_rate);
    }
    $("div").each(function(){
        if (parseInt($(this).attr("id")) <= parseInt(global.count)+1){
            document.getElementById($(this).attr("id")).setAttribute("class", "form-group show");
        }
    });
});
$('#form').submit(function(e) {
    e.preventDefault();
    var str = $('#form').serialize();

    $.ajax('/api/country/rate', {
        type: 'POST',
        data: str,
        dataType: 'json',
        headers: {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
    }).then(function(ret) {
        if(ret.state ==0) {
            alert('贷款利率修改成功');
            location.reload();
        } else {
            alert(ret.message);
        }
    });
});

</script>